import { request } from "../../utils/request.js";
import regeneratorRuntime, { values } from "../../utils/runtime.js";
var bsurl = require('../../utils/bsurl.js');
let flashEvent = require('../../utils/FlashEvent.js')
let app =  getApp();
Component({
  properties: {
    isplay:{
      type:Boolean,
      value:false
    }
  },
  data: {
    musicInfo:{},
    playerData:{},
  },
  methods: {
    //获取音乐信息
    async getmusicInfo(){
      let id=this.data.playerData.playingId
      const playinfo=await request({url: bsurl+'song/detail?ids='+id});
      let musicInfo={
        imageUrl:playinfo.songs[0].al.picUrl,
        name:playinfo.songs[0].name,
        author:playinfo.songs[0].ar[0].name
      }
      this.setData({
        musicInfo
      })
    },
    //返回播放器
    handleNavigateToAudioPlay(){
      let {playerData}=this.data
      wx.navigateTo({
        url: '/pages/playing/index?playId='+playerData.playingId+'&playListId='+playerData.playListId+'&aid='+playerData.albumListId,
      })
    },
    //暂停事件
    isplay(){
      flashEvent.post(flashEvent.EVENT_KEYS.isplay,)
    }

  },
  lifetimes: {
    created() {
      this.setData({
        playerData:app.globalData.playerData,
      })
      if(app.globalData.playerData.isplayer){
        this.getmusicInfo();
      }
      //同步数据更新
      flashEvent.register(flashEvent.EVENT_KEYS.Id, this, function (data) {
        this.setData({
          playerData:data,
        })
        this.getmusicInfo();
      })
       flashEvent.register(flashEvent.EVENT_KEYS.isplayer, this, function (data) {
        this.setData({
          isplay:data
        })
      })
    },
  },
})
